import { BaseItem } from "../common/BaseItem";
import { SPetInfo } from "../../../../Message/Game/SPetInfo";
import { PetUpgradeConfig } from "../../resource/PetUpgradeConfig";
import { PetUtil } from "./info/PetUtil";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../extend/language/Language";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { GameConst } from "../../../component/gconst/GameConst";
import { TPetUpgrage } from "../../../../Message/Db/Tables/TPetUpgrage";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
//class PetUpgradeTipPanel
    
    export  class PetUpgradeTipPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._titleItem = new BaseItem();
            this._titleItem.setSize(33, 32);
            this.addChild(this._titleItem);
            this._holeItem = new BaseItem();
            this._holeItem.setSize(33, 30);
            this._holeItem.move(50, 0);
            this.addChild(this._holeItem);
            return;
        }

        public updateByPet(arg1: Boolean, arg2: SPetInfo, arg3: Boolean=true): void
        {
            var loc1=null;
            var loc2=null;
            this._petInfo = arg2;
            this._isGrowth = arg1;
            var loc3="";
            if (arg1) 
            {
                if (loc2 = PetUpgradeConfig.instance.getInfoByGrade(2, int(arg2.modelLevel))) 
                {
                    loc3 = loc2.title;
                }
                loc1 = PetUtil.getGrowthTitleTipData(arg2.growth);
                if (loc3 != "") 
                {
                    loc1 = loc1 + HTMLUtil.addColor(Language.getStringByParam(54308, loc3), "#00ff00");
                }
                loc1 = loc1 + HTMLUtil.addColor(Language.getString(54309), "#ff0000");
                this._titleItem.toolTipData = loc1;
                this._titlePU = PetUtil.getGrowthTitle(arg2.growth);
            }
            else 
            {
                this._titleItem.toolTipData = PetUtil.getSpiritTitleTipData(arg2.spirit);
                this._titlePU = PetUtil.getSpiritTitle(arg2.spirit);
            }
            this._tileImg = this.getTileImg(this.titlePU);
            this._titleItem.source = this._tileImg;
            if (this.titlePU) 
            {
                this._titleItem.filters = [];
            }
            else 
            {
                this._titleItem.filters = [FilterConst.colorFilter];
            }
            if (arg3) 
            {
                this._holeItem.toolTipData = this.getHoleTip();
                this._holeItem.source = this._holeImg;
                this._holeItem.visible = true;
            }
            else 
            {
                this._holeItem.visible = false;
            }
            return;
        }

        /* internal  */getHoleTip(): string
        {
            var loc5=0;
            var loc6=0;
            var loc7=false;
            var loc8=false;
            var loc9=null;
            var loc10=null;
            var loc1="";
            var loc2="";
            var loc3="";
            var loc4=this._isGrowth ? Language.getString(54191) : Language.getString(54192);
            if (this._isGrowth) 
            {
                loc5 = GameConst.PetGrowthFirstSkill;
                loc6 = GameConst.PetGrowthSecondSkill;
                if (this._petInfo.growthSkillNum != 0) 
                {
                    if (this._petInfo.growthSkillNum != 1) 
                    {
                        if (this._petInfo.growthSkillNum == 2) 
                        {
                            loc7 = true;
                            loc9 = Language.getString(54311);
                            loc8 = true;
                            loc10 = Language.getString(54311);
                        }
                    }
                    else 
                    {
                        loc7 = true;
                        loc9 = Language.getString(54311);
                        loc8 = false;
                        loc10 = Language.getString(54310);
                    }
                }
                else 
                {
                    loc7 = false;
                    loc9 = Language.getString(54310);
                    loc8 = false;
                    loc10 = Language.getString(54310);
                }
            }
            else 
            {
                loc5 = GameConst.PetSpiritFirstSkill;
                loc6 = GameConst.PetSpiritSecondSkill;
                if (this._petInfo.spiritSkillNum != 0) 
                {
                    if (this._petInfo.spiritSkillNum != 1) 
                    {
                        if (this._petInfo.spiritSkillNum == 2) 
                        {
                            loc7 = true;
                            loc9 = Language.getString(54311);
                            loc8 = true;
                            loc10 = Language.getString(54311);
                        }
                    }
                    else 
                    {
                        loc7 = true;
                        loc9 = Language.getString(54311);
                        loc8 = false;
                        loc10 = Language.getString(54310);
                    }
                }
                else 
                {
                    loc7 = false;
                    loc9 = Language.getString(54310);
                    loc8 = false;
                    loc10 = Language.getString(54310);
                }
            }
            this.initImg(loc7, loc8);
            loc1 = loc1 + Language.getString(54312);
            loc1 = loc1 + Language.getStringByParam(54313, loc4, loc5);
            loc1 = loc1 + (Language.getString(54316) + loc9);
            var loc11=loc7 ? "#00ff00" : "#B1efff";
            loc1 = HTMLUtil.addColor(loc1, loc11);
            loc2 = loc2 + Language.getString(54314);
            loc2 = loc2 + Language.getStringByParam(54313, loc4, loc6);
            loc2 = loc2 + (Language.getString(54316) + loc10);
            var loc12=loc8 ? "#00a2ff" : "#B1efff";
            loc2 = HTMLUtil.addColor(loc2, loc12);
            loc3 = Language.getStringByParam(54315, loc4);
            loc3 = HTMLUtil.addColor(loc3, "#ff0000");
            return "<textFormat leading=\'3\' size=\'14\'>" + loc1 + "\n\n" + loc2 + "\n\n" + loc3 + "</textFormat>";
        }

        /* internal  */initImg(arg1: Boolean, arg2: Boolean): void
        {
            if (arg1 != false) 
            {
                if (arg2 != false) 
                {
                    this._holeImg = "petHole2.png";
                }
                else 
                {
                    this._holeImg = "petHole1.png";
                }
            }
            else 
            {
                this._holeImg = "petHole0.png";
            }
            return;
        }

        /* internal  */getTileImg(arg1: TPetUpgrage): string
        {
            var loc1=null;
            if (arg1) 
            {
                loc1 = "petTitle" + arg1.type + arg1.grade + ".png";
            }
            else if (this._isGrowth) 
            {
                loc1 = "petTitle21.png";
            }
            else 
            {
                loc1 = "petTitle11.png";
            }
            return loc1;
        }

        /* internal  */onTileItemMouseOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=this._tileImg.substr(0, this._tileImg.length - 4) + "_over.png";
            this._titleItem.source = loc1;
            return;
        }

        /* internal  */onTileItemMouseOutHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._titleItem.source = this._tileImg;
            return;
        }

        /* internal  */onTitleItemClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._petInfo && this._isGrowth) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetChangeUpgradeModel, this._petInfo.uid));
            }
            return;
        }

        public get titlePU(): TPetUpgrage
        {
            return this._titlePU;
        }

        /* internal */ /* var */_titleItem: BaseItem;

        /* internal */ /* var */_holeItem: BaseItem;

        /* internal */ /* var */_petInfo: SPetInfo;

        /* internal */ /* var */_isGrowth: Boolean;

        /* internal */ /* var */_holeImg: string;

        /* internal */ /* var */_tileImg: string;

        /* internal */ /* var */_titlePU: TPetUpgrage;
    }
